<?php
namespace addons\mall\controller;

use app\common\validate\mall\shop\Shop as Validate;
use addons\mall\model\Goods;
use think\Exception;
use think\exception\PDOException;
use think\exception\ValidateException;
use fast\Tree;
use think\Db;

/**
 * 门店控制器
 */
class Shop extends Base
{

    public function _initialize() {
        parent::_initialize();
        $this->model = new \app\common\model\mall\shop\Shop();

        //配置上传参数
        $upload = \app\common\model\Config::upload();
        \think\Hook::listen("upload_config_init", $upload);
        $this->config['upload'] =  $upload;
        $this->view->assign('config', $this->config);

    }

    /**
     * 店铺街
     */
    public function index()
    {
        $searchword = $this->request->param('searchword');
        $pagesize = $this->request->get('pagesize',10);
        $this->assign('pagesize',$pagesize);

        $filterlist = [];
        $orderlist = [];

        $filter = $this->request->get('filter/a',[]);
        $orderby = $this->request->get('orderby', '');
        $orderway = $this->request->get('orderway', '', 'strtolower');
        $params = ['pagesize' => $pagesize];
        if ($filter)
            $params['filter'] = $filter;
        if ($orderby)
            $params['orderby'] = $orderby;
        if ($orderway)
            $params['orderway'] = $orderway;

        $goodsCats = \app\common\model\mall\goods\Cat::where(['status'=>'normal','showis'=>1,'pid'=>0])
            ->order('weigh asc')->column("id,simplename");

        $fields = [
            ['name' => 'goodscat_ids', 'title' => '经营类目', 'content' => $goodsCats],
        ];
        $filter = array_intersect_key($filter, array_flip(array_column($fields, 'name')));
        foreach ($fields as $v) {
            $content = [];
            $all = ['' => __('All')] + $v['content'];
            foreach ($all as $m => $n) {
                $active = ($m === '' && !isset($filter[$v['name']])) || (isset($filter[$v['name']]) && $filter[$v['name']] == $m) ? TRUE : FALSE;
                $prepare = $m === '' ? array_diff_key($filter, [$v['name'] => $m]) : array_merge($filter, [$v['name'] => $m]);
                $url = '?' . http_build_query(array_merge(['filter' => $prepare], array_diff_key($params, ['filter' => ''])));
                $content[] = ['value' => $m, 'title' => $n, 'active' => $active, 'url' => $url];
            }
            $filterlist[] = [
                'name'    => $v['name'],
                'title'   => $v['title'],
                'content' => $content,
            ];
        }

        $sortrank = [
            ['name' => 'money', 'title' => __('Default')],
            ['name' => 'name', 'title' => __('Name')],
            ['name' => 'id', 'title' => __('Post date')],
        ];
        //设置排序默认值
        $orderby = $orderby && in_array($orderby, ['money', 'name', 'id']) ? $orderby : 'money';
        $orderway = $orderway ? $orderway : 'desc';
        //构建排序数组，以供前端使用
        foreach ($sortrank as $k => $v) {
            $url = '?' . http_build_query(array_merge($params, ['orderby' => $v['name'], 'orderway' => ($orderway == 'desc' ? 'asc' : 'desc')]));
            $v['active'] = $orderby == $v['name'] ? true : false;
            $v['url'] = $url;
            $orderlist[] = $v;
        }

        foreach($filter as $k=>$v){
            if ($k == 'goodscat_ids') {
                $filter[] = ['EXP',Db::raw('FIND_IN_SET('.$v.','.$k.')')];
                unset($filter[$k]);
            }
        }
        if($searchword){
            $pagelist = \addons\mall\model\Shop::alias('s')
                ->join('__USER__ u', 's.user_id = u.id', 'left')
                ->join('__MALL_USER_FAVORITE__ f', 'f.type="shop" and f.target=s.id'.(cookie("uid")? ' and f.user_id=' . cookie("uid") : "") , 'left')
                ->field('s.id,s.shopimg,s.name,s.areaIds,s.longitude,s.latitude,s.shopTel,s.shopQQ,s.shopWangWang,s.money,s.goodscat_ids,u.nickname,u.username,f.id favorite_id')
                ->where(['s.state' => '1', 's.status' => 'normal'])
                ->where("name","like","%".$searchword."%")
                ->paginate($pagesize, false, ['type' => '\\addons\\mall\\library\\Bootstrap']);

        }else {
            //选取正常营业的店铺
            $pagelist = \addons\mall\model\Shop::alias('s')
                ->join('__USER__ u', 's.user_id = u.id', 'left')
                ->join('__MALL_USER_FAVORITE__ f', 'f.type="shop" and f.target=s.id'.(cookie("uid")? ' and f.user_id=' . cookie("uid") : "") , 'left')
                ->field('s.id,s.shopimg,s.name,s.areaIds,s.longitude,s.latitude,s.shopTel,s.shopQQ,s.shopWangWang,s.money,s.goodscat_ids,u.nickname,u.username,f.id favorite_id')
                ->where(['s.state' => '1', 's.status' => 'normal'])
                ->where($filter)
                ->order($orderby, $orderway)
                ->paginate($pagesize, false, ['type' => '\\addons\\mall\\library\\Bootstrap']);
        }
        //获取地区名称
        $exist = \think\Db::query("show tables like'".config('database.prefix')."area'");
        $areas = [];
        if($exist) {
            $areas = db("mall_shop_shop")->alias('s')
                ->where(['s.state'=>'1','s.status'=>'normal'])
                ->join('__AREA__ sa','FIND_IN_SET(sa.id,s.areaIds)','left')
                ->field('s.id shop_id,sa.name')->select();
        }
        //获取主营名称
        $goodscatNames = db("mall_shop_shop")->alias('s')
            ->where(['s.state'=>'1','s.status'=>'normal'])
            ->join('__MALL_GOODS_CAT__ gc','FIND_IN_SET(gc.id,s.goodscat_ids) and gc.status="normal"','left')
            ->field('s.id shop_id,gc.simplename name')->select();
        //获取认证名称
        $list = $pagelist->items();
        $shop_ids = array_column($list,"id");
        $accreds = \app\common\model\mall\shop\AccredAccess::alias("sac")
            ->join('__MALL_SHOP_ACCRED__ a','sac.accred_id=a.id ','left')
            ->where(["sac.shop_id"=>["in" ,$shop_ids],"sac.status"=>"normal"])
            ->field('sac.shop_id,a.name,a.img')
            ->select();
        //获取店铺推荐商品
        $goodsrecom = Goods::where('shop_id', 'in', $shop_ids)
            ->where('status','in',["sale","warn"])
            ->where(['recomis'=>1,'goodsstatus'=>1])
            ->order('saletime desc')
            ->field('id,shop_id,goodsname,shopprice,goodsimg')
            ->select();

        foreach ($list as $key =>$v){
            $list[$key]['totalraty'] = $v['raty']["totalraty5"];
            $list[$key]['goodsraty'] = $v['raty']['goodsraty5'];
            $list[$key]['serviceraty'] = $v['raty']['serviceraty5'];
            $list[$key]['timeraty'] = $v['raty']['timeraty5'];

            $areaNames = "";
            foreach ($areas as $area) {
                if($area['shop_id']==$v['id']) $areaNames .= $area['name'];
            }
            $list[$key]['areas'] = $areaNames;

            $gcNames = [];
            foreach ($goodscatNames as $item) {
                if($item['shop_id']==$v['id']) $gcNames[] = $item['name'];
            }
            $list[$key]['goodscatNames'] = implode(",",$gcNames);

            $acArray = [];
            foreach ($accreds as $item) {
                if($item['shop_id']==$v['id']) $acArray[] = $item;
            }
            $list[$key]['accreds'] = $acArray;
            //商品列表
            $recArray = [];
            foreach ($goodsrecom as $item) {
                if($item['shop_id']==$v['id']) $recArray[] = $item;
            }
            $list[$key]['goods'] = $recArray;
            //店铺商品总数
            $list[$key]['goodsTotal'] = count($list[$key]['goods']);
        }
        $pagelist->appends($list);

        $pagelist->appends($params);
        $this->view->assign("__FILTERLIST__", $filterlist);
        $this->view->assign("__ORDERLIST__", $orderlist);
        $this->view->assign("__PAGELIST__", $pagelist);
        $url = $this->request->url();
        $nav=\app\common\model\mall\oper\Nav::where("navUrl",$url)->select();
        $this->view->assign("__NAV__", $nav);

    	return $this->fetch();
    }

    /**
     * 店铺详情
     */
    public function detail(){
        $shop_id = (int)input("param.ids/d");
        $searchword = input("param.searchword",'');
        $this->assign('searchword',urldecode($searchword));//搜索
        $pagesize = $this->request->get('pagesize',16);
        $this->assign('pagesize',$pagesize);

        $data = [];
        $data['shop'] = $this->model->getShopInfo($shop_id);
        $data['shopcats'] = model('Cat','common\model\mall\shop')->getShopCats($shop_id);
        $this->assign('data',$data);

        $channelList = [];
        $disabledIds = [];
        $all = db("mall_shop_cat")->where(["shop_id"=>$shop_id,"status"=>"normal"])
            ->field("id,name,pid,ismenu,weigh,shop_id")
            ->order("weigh desc,id desc")->select();
        foreach ($all as $k => $v) {
            $state = ['opened' => false];
            if ($v['pid'] == 0) {
                $disabledIds[] = $v['id'];
                $state['checkbox_disabled'] = true;
            }
            $channelList[] = [
                'id'     => $v['id'],
                'parent' => $v['pid'] ? $v['pid'] : '#',
                'text'   => __($v['name']),
                'type'   => $v['ismenu'],
                'state'  => $state
            ];
        }

        $filterlist = [];
        $orderlist = [];
        $filter = $this->request->get('filter/a');
        if(!$filter)$filter=[];
        //本店分类
        $tree = Tree::instance()->init($all, 'pid');
        $shopcat_ids = isset($filter['shopcat_ids'])?$filter['shopcat_ids']:'';
        //$this->assign('shopcat_ids',$shopcat_ids);
        $channelOptions = $tree->getTree(0, "<option model='@shop_id' value=@id @selected @disabled>@spacer@name</option>", $shopcat_ids, $disabledIds);
        $this->view->assign('channelOptions', $channelOptions);
        $this->config['channelList'] =  $channelList;
        $this->view->assign('config', $this->config);


        $orderby = $this->request->get('orderby', '');
        $orderway = $this->request->get('orderway', '', 'strtolower');
        $params = ['ids' => $shop_id,'pagesize'=>$pagesize];
        if ($filter)
            $params['filter'] = $filter;
        if ($orderby)
            $params['orderby'] = $orderby;
        if ($orderway)
            $params['orderway'] = $orderway;

        $fields = [
            ['name' => 'goods_tag', 'title' => '商品标签', 'content' => ['bestis'=>__("bestis"), 'hotis'=>__("Hotis"), 'newis'=>__("Newis"), 'recomis'=>__("Recomis")]],
        ];
        //$filter = array_intersect_key($filter, array_flip(array_column($fields, 'name')));
        foreach ($fields as $v) {
            $content = [];
            $all = ['' => __('All')] + $v['content'];
            foreach ($all as $m => $n) {
                $active = ($m === '' && !isset($filter[$v['name']])) || (isset($filter[$v['name']]) && $filter[$v['name']] == $m) ? TRUE : FALSE;
                $prepare = $m === '' ? array_diff_key($filter, [$v['name'] => $m]) : array_merge($filter, [$v['name'] => $m]);
                $url = '?' . http_build_query(array_merge(['filter' => $prepare], array_diff_key($params, ['filter' => ''])));
                $content[] = ['value' => $m, 'title' => $n, 'active' => $active, 'url' => $url];
            }
            $filterlist[] = [
                'name'    => $v['name'],
                'title'   => $v['title'],
                'content' => $content,
            ];
        }

        $sortrank = [
            ['name' => 'id', 'title' => __('Default')],
            ['name' => 'visitnum', 'title' => __('Visitnum')],
            ['name' => 'salenum', 'title' => __('Salenum')],
            ['name' => 'shopprice', 'title' => __('Shopprice')],
            ['name' => 'appraisenum', 'title' => __('Appraisenum')],
            ['name' => 'saletime', 'title' => __('Saletime')],
        ];
        //第二次单击，排序顺序取反
        $orderby = $orderby && in_array($orderby, ['id', 'visitnum', 'salenum', 'shopprice', 'appraisenum', 'saletime']) ? $orderby : 'id';
        //默认为降序
        $orderway = $orderway ? $orderway : 'desc';
        //构建排序数组，以供前端使用
        foreach ($sortrank as $k => $v) {
            $url = '?' . http_build_query(array_merge($params, ['orderby' => $v['name'], 'orderway' => ($orderway == 'desc' ? 'asc' : 'desc')]));
            $v['active'] = $orderby == $v['name'] ? true : false;
            $v['url'] = $url;
            $orderlist[] = $v;
        }

        foreach($filter as $k=>$v){
            if($k=="goods_tag") {
                $filter[$v] = 1;
            }elseif($k=="shopcat_ids"){
                $filter[] = ['EXP',Db::raw('FIND_IN_SET('.$v.','.$k.')')];
            }elseif($k=="shopprice"){
                $p = explode('-',$v);
                if($p[0]!='' && $p[1]!=''){
                    $filter['shopprice'] = ['between',[(int)$p[0],(int)$p[1]]];
                }elseif($p[0]!=''&& $p[1]==''){
                    $filter['shopprice'] = ['>=',(int)$p[0]];
                }

            }
            unset($filter[$k]);
        }
        //获取店铺推荐商品
        $pagelist = Goods::where('shop_id', '=', $shop_id)
            ->where('status','in','sale,warn')
            ->where($filter)
            ->order($orderby, $orderway)
            ->field('id,shop_id,goodsname,shopprice,goodsimg,bestis,hotis, newis,recomis,salenum,saletime,visitnum,appraisenum')
            ->paginate($pagesize, false, ['type' => '\\addons\\mall\\library\\Bootstrap']);

        //处理关注
        if(cookie('uid')){
            $f = model('\app\common\model\mall\user\Favorite');
            foreach($pagelist as $k=>$v){
                $pagelist[$k]['favShop'] = $f->checkFavorite($v['shop_id'],'shop');
                $pagelist[$k]['favGood'] = $f->checkFavorite($v['id'],'goods');
            }
        }
        $pagelist->appends($params);
        $this->view->assign("__FILTERLIST__", $filterlist);
        $this->view->assign("__ORDERLIST__", $orderlist);
        $this->view->assign("__PAGELIST__", $pagelist);
        //渲染当前导航菜单
        //$nav=\app\common\model\mall\shop\Cat::get($shopcat_ids);
        $this->view->assign("__NAV__", []);

    	return $this->fetch();
    }

    /**
     * 商家入驻
     */
    public function join(){
        $rs = $this->model->checkApply();
        //是否可申请
        $this->assign('isApply',(empty($rs)?true:false));
        //是否可编辑
        $this->assign('enbleEdit',(!empty($rs) && in_array($rs['status'],["fillin","reject"]))?true:false);
        $this->assign('applyStep',empty($rs)?1:$rs['applyStep']);
        $articles = model('Help','common\model\mall\oper')->getHelpByCat(13);
        // 防止不存在入驻文章时报错
        if(!isset($articles['38']))$articles['38']['acontent'] = '无相关说明,请咨询商城客服~';
        if(!isset($articles['39']))$articles['39']['acontent'] = '无相关说明,请咨询商城客服~';
        if(!isset($articles['40']))$articles['40']['acontent'] = '无相关说明,请咨询商城客服~';
        if(!isset($articles['41']))$articles['41']['acontent'] = '无相关说明,请咨询商城客服~';
        $this->assign('artiles',$articles);
        return $this->fetch();
    }

    /**
     * 入驻协议
     */
    public function joinstep1(){
        session('apply_step',1);
        if ($this->request->isPost()) {
            $this->success('', addon_url('mall/shop/joinstep2'));
        }
        $rs = $this->model->checkApply();
        $articles = model('Help','common\model\mall\oper')->getHelpByCat(53);
        // 防止不存在入驻文章时报错
        if(!isset($articles['42']))$articles['42']['acontent'] = '无相关说明,请咨询商城客服~';
        $this->assign('artiles',$articles);
        return $this->fetch();
    }

    /**
     * 入驻人联系方式
     */
    public function joinstep2(){
        $step = (int)session('apply_step');

        if ($this->request->isPost()) {
            if($step<2){
                return $this->result('请勿跳过申请步骤');
            }
            $data = $this->request->post("row/a");
            if($data){
                $user_id = (int)cookie('uid');
                //判断是否存在入驻申请
                $shops = $this->model->where('user_id',$user_id)->find();
                //新增入驻申请
                Db::startTrans();
                try{
                    $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
                    $validate = $name . '.applyStep1';
                    $this->model->validateFailException(true)->validate($validate);
                    if(empty($shops)){

                        $shop = ['user_id'=>$user_id,'status'=>"fillin",'applyStep'=>2];
                        $this->model->data($shop,true)->isUpdate(false)->allowField(true)->save();

                        $data['shop_id'] = $this->model->id;
                        $result = Db::name('mall_shop_extra')->insert($data);

                        $MALL_USER = session('MALL_USER');
                        $MALL_USER['tempShopId'] = $this->model->id;
                        session('MALL_USER',$MALL_USER);

                    }else{
                        if(!in_array($shops['status'],["fillin","reject"]))$this->error('请勿重复申请入驻');
                        if($shops->applyStep<2){
                            $shops->applyStep = 2;
                            $shops->allowField(true)->save();
                        }
                        $result = Db::name('mall_shop_extra')->where('shop_id',$shops['id'])->update($data);
                    }
                    if(false !== $result){
                        Db::commit();
                        return $this->success('',addon_url('mall/shop/joinstep3'));
                    }else{
                        Db::rollback();
                        $this->error('保存失败');
                    }
                } catch (ValidateException $e) {
                    Db::rollback();
                    $this->error($e->getMessage());
                } catch (PDOException $e) {
                    Db::rollback();
                    $this->error($e->getMessage());
                } catch (Exception $e) {
                    Db::rollback();
                    $this->error($e->getMessage());
                }
            }
        }

        if($step<1){
            $this->redirect(addon_url('mall/shop/joinstep1'));
            exit();
        }
        session('apply_step',2);
        $apply = $this->model->getShopApply();
        $this->assign('apply',$apply);
        return $this->fetch();
    }

    /**
     * 公司证照信息
     */
    public function joinstep3(){
        $step = (int)session('apply_step');

        if ($this->request->isPost()) {
            if($step<3){
                return $this->result('请勿跳过申请步骤');
            }
            $data = $this->request->post("row/a");
            if($data){
                $shop_id = (int)session('MALL_USER.tempShopId');
                if($shop_id==0) $this->error('非法的操作');
                $shops = $this->model->get($shop_id);
                if(!in_array($shops['status'],["fillin","reject"])) $this->error('请勿重复申请入驻');
                if($data['LongbusinessDateis']==1) unset($data['businessEndDate']);
                if($data['LonglegalCertificateDateis']==1) unset($data['legalCertificateEndDate']);
                if($data['LongOrganizationCodeDateis']==1) unset($data['organizationCodeEndDate']);
                Db::startTrans();
                try{
                    $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
                    $validate = $name . '.applyStep2';
                    $this->model->validateFailException(true)->validate($validate);

                    if($shops->applyStep<3){
                        $shops->applyStep = 3;
                        $shops->save();
                    }
                    $seModel = new \app\common\model\mall\shop\Extra;
                    $result1 = $seModel->isUpdate(true)->allowField(true)->save($data,['shop_id'=>$shop_id]);

                    //将注册地id,复制为公司所在地和开户银行所在地
                    $data['bankAreaIds'] = $data['businessAreaPath'];
                    $data['areaIds'] = $data['businessAreaPath'];
                    $result2 = $this->model->isUpdate()->allowField(true)->save($data,['id'=>$shop_id]);

                    if(false !== $result1||$result2){
                        Db::commit();
                        $this->success('', '/addons/mall/shop/joinstep4');
                    }else{
                        Db::rollback();
                        $this->error('保存失败');
                    }
                } catch (ValidateException $e) {
                    Db::rollback();
                    $this->error($e->getMessage());
                } catch (PDOException $e) {
                    Db::rollback();
                    $this->error($e->getMessage());
                } catch (Exception $e) {
                    Db::rollback();
                    $this->error($e->getMessage());
                }
            }
        }

        if($step<2){
            $this->redirect(addon_url('mall/shop/joinstep1'));
            exit();
        }
        session('apply_step',3);
        $apply = $this->model->getShopApply();
        $this->assign('apply',$apply);

        $extraModel = new \app\common\model\mall\shop\Extra;
        $this->view->assign("businesslicencetypeList", $extraModel->getBusinesslicencetypeList());
        $this->view->assign("legalcertificatetypeList", $extraModel->getLegalcertificatetypeList());
        $this->view->assign("taxpayertypeList", $extraModel->getTaxpayertypeList());

        return $this->fetch();
    }

    /**
     * 财务及基本信息
     */
    public function joinstep4(){
        $step = (int)session('apply_step');

        if ($this->request->isPost()) {
            if($step<4){
                return $this->result('请勿跳过申请步骤');
            }
            $data = $this->request->post("row/a");
            if($data){
                $shop_id = (int)session('MALL_USER.tempShopId');
                if($shop_id==0)$this->error('非法的操作');
                $shops = $this->model->get($shop_id);
                if(!in_array($shops['status'],["fillin","reject"]))$this->error('请勿重复申请入驻');
                Db::startTrans();
                try{
                    $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
                    $validate = $name . '.applyStep3';
                    $this->model->validateFailException(true)->validate($validate);

                    if($shops->applyStep<4){
                        $shops->applyStep = 4;
                        $shops->save();
                    }
                    //将公司名称,复制为店铺名称
                    $data['name'] = $data['shopCompany']."旗舰店";
                    $result = $this->model->allowField(true)->save($data,['id'=>$shop_id]);

                    if(false !== $result){
                        Db::commit();
                        $this->success('',addon_url('mall/shop/joinstep5'));
                    }else{
                        Db::rollback();
                        $this->error('保存失败');
                    }
                } catch (ValidateException $e) {
                    Db::rollback();
                    $this->error($e->getMessage());
                } catch (PDOException $e) {
                    Db::rollback();
                    $this->error($e->getMessage());
                } catch (Exception $e) {
                    Db::rollback();
                    $this->error($e->getMessage());
                }
            }
        }

        if($step<3){
            $this->redirect(addon_url('mall/shop/joinstep1'));
            exit();
        }
        session('apply_step',4);
        $apply = $this->model->getShopApply();
        $this->assign('apply',$apply);
        return $this->fetch();
    }

    /**
     * 店铺信息
     */
    public function joinstep5(){
        $step = (int)session('apply_step');

        if ($this->request->isPost()) {
            if($step<5){
                return $this->result('请勿跳过申请步骤');
            }
            $data = $this->request->post("row/a");
            if($data){
                $shop_id = (int)session('MALL_USER.tempShopId');
                if($shop_id==0)$this->error('非法的操作');
                $shops = $this->model->get($shop_id);
                if(!in_array($shops['status'],["fillin","reject"]))$this->error('请勿重复申请入驻');
                Db::startTrans();
                try{
                    $data['status'] = "audit";

                    $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
                    $validate = $name . '.applyStep4';
                    $this->model->validateFailException(true)->validate($validate);

                    $result = $this->model->allowField(true)->save($data,['id'=>$shop_id]);
                    if($shops->applyStep<5){
                        $shops->applyStep = 5;
                        $shops->save();
                    }
                    if(false !== $result){
                        Db::commit();
                        $this->success('',addon_url('mall/shop/joinsuccess'));
                    }
                    else{
                        Db::rollback();
                        $this->error('保存失败');
                    }
                } catch (ValidateException $e) {
                    Db::rollback();
                    $this->error($e->getMessage());
                } catch (PDOException $e) {
                    Db::rollback();
                    $this->error($e->getMessage());
                } catch (Exception $e) {
                    Db::rollback();
                    $this->error($e->getMessage());
                }
            }
        }

        if($step<4) {
            $this->redirect(addon_url('mall/shop/joinstep1'));
            exit();
        }
        session('apply_step',5);
        $goodsCatList = model('Cat','common\model\mall\goods')->listQuery(0);
        $this->assign('goodsCatList',$goodsCatList);
        $apply = $this->model->getShopApply();
        $this->assign('apply',$apply);
        return $this->fetch();
    }

    /**
     * 入驻审核
     */
    public function joinsuccess(){
        $step = (int)session('apply_step');
        if($step<5){
            $this->redirect(addon_url('mall/shop/joinstep1'));
        }
        session('apply_step',5);
        $apply = $this->model->getShopApply();
        $this->assign('apply',$apply);
        return $this->fetch();
    }

    /**
     * 入驻进度查询
     */
    public function joinstatus(){
        $apply = $this->model->getShopApply();
        if(empty($apply)){
            $this->redirect(addon_url('mall/shop/joinstep1'));
            exit();
        }else{
            if(in_array($apply['status'],["fillin"])){
                session('apply_step',$apply['applyStep']);
                $this->redirect(addon_url('mall/shop/joinstep'.$apply['applyStep']));
                exit();
            }else{
                $this->assign('apply',$apply);
                return $this->fetch('joinSuccess');
            }
        }
    }

}
